package com.yuantu.judiciary.model.word;

import lombok.Data;
import org.apache.poi.xwpf.usermodel.BreakType;
import org.apache.poi.xwpf.usermodel.UnderlinePatterns;
import org.apache.poi.xwpf.usermodel.VerticalAlign;
import org.apache.poi.xwpf.usermodel.XWPFRun;

/**
 * @author kgwei
 * 段落中的文字
 */
@Data
public class WordText {

    private String text;

    private Boolean bold;

    private  Integer fontSize;

    private String fontFamily;

    /**
     * @see UnderlinePatterns
     * UnderlinePatterns.DOT_DOT_DASH
     */
    private UnderlinePatterns underline;

    private Integer textPosition;

    /**
     * @see VerticalAlign
     * VerticalAlign.SUPERSCRIPT
     */
    private VerticalAlign subscript;

    private WordHyperLink hyperLink;

    /**
     * @see BreakType
     * BreakType.PAGE
     */
    private BreakType breakType;

    private Boolean italic;

    private Boolean addCarriageReturn;

    private String color;

    void textBuild(XWPFRun r) {
        r.setText(text);
        if (bold != null) {
            r.setBold(bold);
        }
        if (fontSize != null) {
            r.setFontSize(fontSize);
        }
        if (fontFamily != null) {
            r.setFontFamily(fontFamily);
        }
        if (underline != null) {
            r.setUnderline(underline);
        }
        if (textPosition != null) {
            r.setTextPosition(textPosition);
        }
        if (subscript != null) {
            r.setSubscript(subscript);
        }
        if (breakType != null) {
            r.addBreak(breakType);
        }
        if (italic != null) {
            r.setItalic(italic);
        }
        if (addCarriageReturn != null && addCarriageReturn) {
            r.addCarriageReturn();
        }
        if(color !=null){
            r.setColor(color);
        }
    }
}
